﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace DuelQuizzServer
{
    public partial class Result
    {
        private static Entities context;
        private static DbSet<Result> entities
        {
            get
            {
                if (Result.context == null)
                {
                    Result.context = new Entities();
                    Result.context.Configuration.ProxyCreationEnabled = false;
                    Result.context.Configuration.LazyLoadingEnabled = true;
                }
                return context.Result;
            }
        }

        internal static void add(Result result)
        {
            Result.entities.Add(result);
            Result.context.SaveChanges();
        }

        internal static List<Result> getResults(int user_id)
        {
            try
            {
                return entities.Where(p => (p.user_id == user_id)).OrderByDescending(p => p.date).ToList();
            }
            catch (Exception e)
            {
                return new List<Result>();
            }
        }
    }
}